<%@ page contentType="text/html" %>
<%@ taglib prefix="jbfilter" uri="http://jbfilter.org/tag" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:useBean id="dao" class="org.jbfilter.test.beans.factory.DataAccessObject" scope="application"/>
<c:set var="datePattern" value="dd/MM/yyyy HH:mm:ss"/>
<c:set var="checked">checked="checked"</c:set>
<c:set var="selected">selected="selected"</c:set>
<c:set var="truncateClass" value="org.jbfilter.core.TruncateUnit"/>

<html>
<head>
<title>DateFilterComponent</title>
</head>
<body>

<jbfilter:filter id="myFilterDate" varComponents="comps" providerName="bean" clean="${param.clean}">
	<jbfilter:dateComponent
		id="fc"
		propertyPath="${param.propertyPath}"
		value="${param.value}"
		pattern="${datePattern}"
		inverted="${param.inverted}"
		enabled="${!param.disabled}"
		valueCleanValue="${param.valueCleanValue}"
		nullTestingEnabled="${param.nullTestingEnabled}"
		valueForNull="${param.valueForNull}"
		comparatorKeyword="${param.comparatorKeyword}"
		comparatorKeywordCleanValue="${param.comparatorKeywordCleanValue}"
		truncate="${param.truncate}"
		/>
</jbfilter:filter>

<form action="">
	<table>
		<tr>
			<td>propertyPath</td>
			<td>
				<select name="propertyPath">
					<option value="born"<c:if test="${comps.fc.propertyPath == 'born'}"> ${selected}</c:if>>born</option>
					<option value="died"<c:if test="${comps.fc.propertyPath == 'died'}"> ${selected}</c:if>>died</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>comparatorKeyword</td>
			<td>
				<select name="comparatorKeyword">
					<option value="gt"<c:if test="${comps.fc.comparatorKeyword == 'gt'}"> selected="selected"</c:if>>&gt;</option>
					<option value="ge"<c:if test="${comps.fc.comparatorKeyword == 'ge'}"> selected="selected"</c:if>>&gt;=</option>
					<option value="eq"<c:if test="${comps.fc.comparatorKeyword == 'eq'}"> selected="selected"</c:if>>=</option>
					<option value="lt"<c:if test="${comps.fc.comparatorKeyword == 'lt'}"> selected="selected"</c:if>>&lt;</option>
					<option value="le"<c:if test="${comps.fc.comparatorKeyword == 'le'}"> selected="selected"</c:if>>&lt;=</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>value</td>
			<td><input type="text" name="value" value="<fmt:formatDate value="${comps.fc.value}" pattern="${datePattern}"/>"/></td>
		</tr>
		<tr>
			<td>truncate</td>
			<td>
				<select name="truncate">
					<option value="">N/A</option>
					<jbfilter:forEachEnum enumClass="${truncateClass}" var="curr">
						<option value="${curr}"<c:if test="${comps.fc.truncate == curr}">selected="selected"</c:if>>${curr}</option>
					</jbfilter:forEachEnum>
				</select>
			</td>
		</tr>
		<tr>
			<td>valueCleanValue </td>
			<td><input type="text" name="valueCleanValue" value="<fmt:formatDate value="${comps.fc.valueCleanValue}" pattern="${datePattern}"/>"/></td>
		</tr>
		<tr>
			<td>comparatorKeywordCleanValue</td>
			<td>
				<select name="comparatorKeywordCleanValue">
					<option value="gt"<c:if test="${comps.fc.comparatorKeywordCleanValue == 'gt'}"> selected="selected"</c:if>>&gt;</option>
					<option value="ge"<c:if test="${comps.fc.comparatorKeywordCleanValue == 'ge'}"> selected="selected"</c:if>>&gt;=</option>
					<option value="eq"<c:if test="${comps.fc.comparatorKeywordCleanValue == 'eq'}"> selected="selected"</c:if>>=</option>
					<option value="lt"<c:if test="${comps.fc.comparatorKeywordCleanValue == 'lt'}"> selected="selected"</c:if>>&lt;</option>
					<option value="le"<c:if test="${comps.fc.comparatorKeywordCleanValue == 'le'}"> selected="selected"</c:if>>&lt;=</option>
				</select>
			</td>
		</tr>
		<tr>
			<td>valueForNull </td>
			<td><input type="text" name="valueForNull" value="${param.valueForNull}"/></td>
		</tr>
		<tr>
			<td>inverted</td>
			<td><input type="checkbox" name="inverted" value="true"<c:if test="${comps.fc.inverted}"> ${checked}</c:if>/>inverted</td>
		</tr>
		<tr>
			<td>disabled</td>
			<td><input type="checkbox" name="disabled" value="true"<c:if test="${!comps.fc.enabled}"> ${checked}</c:if>/>disabled</td>
		</tr>
		<tr>
			<td>nullTestingEnabled</td>
			<td><input type="checkbox" name="nullTestingEnabled" value="true"<c:if test="${comps.fc.nullTestingEnabled}"> ${checked}</c:if>/>nullTestingEnabled</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>
				<input type="submit" value="Ok"/>
				<input type="submit" name="clean" value="Clean"/>
			</td>
		</tr>
	</table>
</form>

<jbfilter:doFilter
	filterId="myFilterDate"
	items="${dao.allComposers}"
	varFilteredItems="filteredComposers"/>

<table border="1">
	<thead>
		<tr>
			<td>id</td>
			<td>Name</td>
			<td>born</td>
			<td>died</td>
			<td>country</td>
		</tr>
	</thead>
	<tbody>
		<c:forEach items="${filteredComposers}" var="composer">
			<tr>
				<td>${composer.id}</td>
				<td>${composer.name}</td>
				<td><fmt:formatDate value="${composer.born}" pattern="${datePattern}"/></td>
				<td><c:if test="${empty composer.died}">&nbsp;</c:if><fmt:formatDate value="${composer.died}" pattern="${datePattern}"/></td>
				<td>${composer.country}</td>
			</tr>
		</c:forEach>
	</tbody>
</table>
comps.fc.propertyPath : ${comps.fc.propertyPath}<br/>
comps.fc.value : ${comps.fc.value}<br/>
comps.fc.truncate: ${comps.fc.truncate}<br/>
comps.fc.inverted : ${comps.fc.inverted}<br/>
comps.fc.enabled : ${comps.fc.enabled}<br/>
comps.fc.nullTestingEnabled : ${comps.fc.nullTestingEnabled}<br/>
comps.fc.active : ${comps.fc.active}<br/>
comps.fc.value == null : ${comps.fc.value == null}<br/>
comparatorKeyword : ${comps.fc.comparatorKeyword}<br/>
${comps}

</body>

</html>